def sv(arr):
    print(id(arr), arr)


def sep(label='', n=32):
    n = int(n)
    label = str(label)
    if len(label) == 0:
        print('-' * n, flush=True)
    else:
        half_n = n // 2
        print('-' * half_n, label, '-' * half_n, sep='', flush=True)


def input_value(xtype, xprompt, *args, xerror_prompt='您的输入有误，请重新输入！', xis_strip=True, **kwargs):
    print(xprompt)
    for k, v in kwargs.items():
        print('\t>', repr(k), repr(v))
    xinput = input()
    if xis_strip:
        xinput = xinput.strip()
    try:
        value = xtype(xinput)
    except ValueError:
        print(xerror_prompt)
        return None
    for xlambda, xlambda_error_prompt in args:
        if xlambda is None:
            xlambda = xlambda_error_prompt
            try:
                value = xlambda(value)
            except ValueError:
                print(xerror_prompt)
                return None
        if xlambda_error_prompt is None:
            xlambda_error_prompt = xerror_prompt
        try:
            xr = xlambda(value)
            if not(xr):
                print(xlambda_error_prompt)
                return None
        except ValueError:
            print(xlambda_error_prompt)
            return None
    return value


def input_value_util_well(xtype, xprompt, *args, xerror_prompt='您的输入有误，请重新输入！', xis_strip=True, **kwargs):
    while True:
        value = input_value(xtype, xprompt, *args, xerror_prompt=xerror_prompt, xis_strip=xis_strip, **kwargs)
        if value is None:
            continue
        else:
            return value


def xcheck(v, label=''):
    print(f'id={id(v)}, type={type(v)}, repr={v!r}, label={label!s}')


def xshow_table(xlist):
    n = 1
    for xrow in xlist:
        print(f'{n}: ', end='')
        for xelement in xrow:
            print(repr(xelement), end='; ')
        print()
        n += 1


def xshow_list(xlist):
    n = 1
    for xrow in xlist:
        print(f'{n}: {xrow!r}')
        n += 1


def xshow_dict(xdict):
    n = 1
    for xkey, xrow in xdict.items():
        print(f'{n}: {xkey!r} => {xrow!r}')
        n += 1


def xeval(exp, **kwargs):
    tgt = exp
    for k in kwargs:
        tgt = tgt.replace(k, f'kwargs["{k}"]')
    print(exp, '=>', eval(tgt))
